* Set up data to be used in JULIA for KSS analysis (footnote 37), and compare with estimates using the baseline shrinkage approach in this sample

clear all


* KSS uses a connected set with multiple (4 or more) connectors
use "$savedata/revisions_connect_total25.dta", clear
keep if akm_connectors>3
save "$savedata/kss_set.dta", replace


use "$savedata/masterdata.dta", replace

merge m:1 trust_code using "$savedata/kss_set.dta"
keep if _merge==3

keep if sample25==1
gen vol = vol25


* First check what variance looks like in this sample when using my typical shrinkage approach but without controls

reghdfe survive30, absorb(i.finyear i.hyid, savefe) keepsingleton
predict residual30, residuals

xtreg residual30, fe i(doctor_id)
predict docfe30, u
gen sigma_u30 = e(sigma_u)
gen sigma_e30 = e(sigma_e)


collapse (mean) docfe* residual* sigma* vol, by(doctor_id)

gen signal_2step30 = ((sigma_u30^2) / ((sigma_u30^2) + ((sigma_e30^2)/vol)))
gen adj_docfe30 = docfe30*signal_2step30

* Variance and SD here
su adj*


* Keep variables required for JULIA programme to implement KSS
keep survive30 survive365 prevyear_cost sex derv_age black mixed chinese asian race_miss ynch* prevyear_stroke di1 di2 di3 di4 di5 shock arythmia arthero arrest dow admidate_mont finyear hyid doctor_id vol trust_num

save "$savedata/kss_analysis_data.dta", replace

save "$savedata/kss_analysis_data.csv", replace


* This file is then used with the JULIA programme available here: ADD FILEPATH
